﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace milanov
{
    //Thom
    public partial class manageorders : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //deze code zorgt ervoor dat alleen admins op deze page kunnen komen
            if (!Fotos.isAdmin(User.Identity.Name))
            {
                Server.Transfer("Default.aspx");
            }
            getallorders();
        }
        /// <summary>
        /// methode die alle orders uit de database haalt, met de bijpassende gebruikersnaam, email
        /// deze sorteert de orders bij completed, afgehandelde komen bovenaan.
        /// </summary>
        public void getallorders()
        {
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["fotosDB"].ConnectionString))
            {
                string query = "SELECT u.UserName, m.Email, o.* FROM Users u, Memberships m, Orders o WHERE o.OrderId IS NOT NULL AND u.UserId = o.UserId AND m.UserId = u.UserId ORDER BY o.Completed DESC";
                using (SqlDataAdapter da = new SqlDataAdapter(query, con))
                {
                    DataTable dt = new DataTable();
                    da.Fill(dt);
                    ordergrid.DataSource = dt;
                    ordergrid.DataBind();
                }
            }
        }
    }
}